<template>
  <ul class="footer">
    <li @click="toIndex" :class="{ active: isActive('/index') }">
      <i class="fa fa-home"></i>
      <p>首页</p>
    </li>
    <li @click="toDiscovery" :class="{ active: isActive('/discovery') }">
      <i class="fa fa-compass"></i>
      <p>发现</p>
    </li>
    <li @click="toOrderList" :class="{ active: isActive('/orderList') }">
      <i class="fa fa-file-text-o"></i>
      <p>订单</p>
    </li>
    <li @click="toUserInfo" :class="{ active: isActive('/userInfo') }">
      <i class="fa fa-user-o"></i>
      <p>我的</p>
    </li>
  </ul>
</template>

<script setup>
import { useRouter, useRoute } from "vue-router";
import { computed } from "vue";

const router = useRouter();
const route = useRoute();

// 根据当前路径判断是否激活
const isActive = (path) => {
  return route.path === path;
};

// 导航处理函数
const toIndex = () => {
  router.push({ path: "/index" });
};

const toDiscovery = () => {
  router.push({ path: "/discovery" });
};

const toOrderList = () => {
  router.push({ path: "/orderList" });
};
const toUserInfo = () => {
  router.push({ path: "/userInfo" });
};
</script>

<style scoped>
.footer {
  width: 100%;
  height: 14vw;
  border-top: solid 1px #ddd;
  background-color: #fff;

  position: fixed;
  left: 0;
  bottom: 0;
  z-index: 999;

  display: flex;
  justify-content: space-around;
  align-items: center;
}

.footer li {
  /*li本身的尺寸完全由内容撑起*/
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;

  color: #999;
  user-select: none;
  cursor: pointer;
}

.footer li.active {
  color: #0097ff;
}

.footer li.active i,
.footer li.active p {
  color: #0097ff;
}

.footer li p {
  font-size: 2.8vw;
}

.footer li i {
  font-size: 5vw;
}
</style>